import axios from "axios";
import {
  injectCommonParams,
  injectHeader,
  // injectCustomParams,
  // injectLogin,
  injectSwitchContentType,
  // switchUrl,
  requestInterceptorsSuccess,
  requestInterceptorsFail,
  responseInterceptorsSuccess,
  responseInterceptorsFail,
  businessResponse,
  injectHash,
  releaseHash
} from "./interceptors";
import {
  API_URL
} from "./config";

// import "./collect";

const instance = axios.create({
  baseURL: API_URL,
  timeout: 0 * 1000,
  withCredentials: false
});

// @ts-ignore
instance.interceptors.request.use(injectHash);
instance.interceptors.request.use(injectSwitchContentType);
instance.interceptors.request.use(injectHeader);
instance.interceptors.request.use(injectCommonParams);
instance.interceptors.request.use(requestInterceptorsSuccess, requestInterceptorsFail);

instance.interceptors.response.use(releaseHash);
instance.interceptors.response.use(responseInterceptorsSuccess);
// @ts-ignore 自定义格式
instance.interceptors.response.use(businessResponse, responseInterceptorsFail);

export default instance;
